package compositePattern;

import java.util.ArrayList;
import java.util.List;

/**
 * 菜单
 */
public class Menu extends MenuComponent{

    private List<MenuComponent> menus;

    public Menu(String name, int level) {
        this.name = name;
        this.level = level;
        this.menus = new ArrayList<MenuComponent>();
    }

    @Override
    public void print() {
        for (int i = 0; i < level; i++) {
            System.out.print("--");
        }
        System.out.println(name);
        for (MenuComponent menu : menus) {
            menu.print();
        }
    }

    public boolean add(MenuComponent menuComponent) {
        return menus.add(menuComponent);
    }

    public MenuComponent remove(int index) {
        return menus.remove(index);
    }

    public MenuComponent get(int index) {
        return menus.get(index);
    }
}
